datapath='\\KELLER-RIG1-2PI\tempData\tempData\S1-T';
outputpath = '\\argon.fmi.ch\keller.g\temp\ml\jove\';
stacks = [6956 6957 6958 6960 6961 6962];
for ind=1:length(stacks)
    data = load_bin([datapath num2str(stacks(ind)) '_ch525.bin']);
    [dx, dy] = register_frames(data);
    data = shift_data(data,dx,dy);
    data=correct_line_shift(data,mean(data,3));
    avg=mean(data,3);
    avg2=mean(data(:,:,20:21),3);
    avg5=mean(data(:,:,20:24),3);
    imwrite(scaleImage(avg), [outputpath num2str(stacks(ind)) '_avg.tif']);
    imwrite(scaleImage(avg2), [outputpath num2str(stacks(ind)) '_avg2.tif']);
    imwrite(scaleImage(avg5), [outputpath num2str(stacks(ind)) '_avg5.tif']);
end
